<?php

namespace app\store\model;

use think\Model;

class Invoice extends Model
{
    protected $name = 'invoice';
     // 关闭本模型的时间自动写入与格式化（覆盖全局）
    protected $autoWriteTimestamp = false;  // 不自动写时间戳
    protected $dateFormat = false;          // 读取时不做 date() 格式化
    protected $createTime = 'create_time';  // 仅声明字段名（不自动维护）
    protected $updateTime = 'update_time';
    /**
     * 获取开票列表
     */
    public function getList($query = [])
    {
        $where = [];
        if (!empty($query['invoice_type'])) {
            $where['invoice_type'] = $query['invoice_type'];
        }
        if (!empty($query['status'])) {
            $where['status'] = $query['status'];
        }
        if (!empty($query['invoice_title'])) {
            $where['invoice_title'] = ['like', "%{$query['invoice_title']}%"];
        }

        return $this->where($where)
            ->order(['create_time' => 'desc'])
            ->paginate(15, false, [
                'query' => \request()->request()
            ]);
    }

    /**
     * 获取详情
     */
    public static function detail($invoice_id)
    {
        return self::get($invoice_id);
    }
}